const app = getApp()
const utils = require('../../../../common/util/util')
const text = require('../../../../common/util/text')
Page({
  data: {
    userInfo:{},
    needSetting:app.globalData.needAuthorization
  },
  onLoad: function (options) {
    let that=this;
    that.xGetUser()
    that.xService(options.channel_id)
  },
  onShareAppMessage: function () {
    // return {
    //   title:  this.data.xProduct.name ,
    //   path: '/subsale/pages/product/index/index?id='+ this.data.xProduct._id ,
    //   imageUrl: 'https://7633-v3-92ah4-1300208657.tcb.qcloud.la/static/share_product.jpg?sign=b6492ec3cc1a12539d39b08d1d12b0d5&t=1657171251',
    // };
  },
  // 用户信息
  xGetUser(){
    let that = this
    wx.cloud.callFunction({
      name : 'user' ,
      data : {
          action : 'detail'
      }
    }).then( res => {
      that.setData({
        userInfo:res.result
      })
    })
  },
  // 开通服务
  xService:function(channel_id){
    let that=this;
    // 获取详情
    wx.cloud.callFunction({
      name: 'channel_management',
      data: {
        action: "get_channel_info",
        channel_id: channel_id
      }
    }).then(res => {
      res.result.content = text.text(res.result.content)
      that.setData({
        channelInfo:res.result
      })
    })
    // 开通服务
    wx.cloud.callFunction({
      name: 'channel_management',
      data: {
        action: "subscription_service",
        channel_id: channel_id
      }
    }).then(res => {
    })
  },
  handleTouchInput:function(){
    this.setData({
      innerShow:true
    })
  },
  changePrivacySetting:function(e){
    this.setData({
      needSetting:false
    })
  },
  xPhone: async function (e) {
      let that = this
      let params = e.currentTarget.dataset
      wx.showLoading({
          title: '请稍等',
      })
      await wx.cloud.callFunction({
          name: 'user',
          data: {
              action: 'getPhone',
              cloudID: e.detail.cloudID
          },
          success: function (res) {
            that.xUserEdit({phone_number:res.result.phoneNumber})
          }
      })
      wx.hideLoading()
  },
  xUserEdit(form){
    wx.cloud.callFunction({
      name: "user",
      data: {
          action: "edit",
          formdata: form
      }
    }).then(res => {
      wx.reLaunch({
        url: '/pages/navigation/using/index',
      })
      app.globalData.xCustomer.phone_number = form.phone_number
    })
  },
  xNext:function(){
    wx.reLaunch({
      url: '/pages/navigation/using/index',
    })
  }
})